import request from '@/request/request'

// 创建销售订单
export function createSales(salesOrder) {
    return request({
        method: "post",
        url: '/sales',
        data: salesOrder
    })
}

// 获取客户列表
export function getCustomer() {
    return request({
        method: "get",
        url: '/sales/customer',
    })
}

// 删除销售订单
export function deleteSales(id) {
    return request({
        method: "delete",
        url: `/sales/${id}`,
    })
}

// 更新销售订单
export function updateSales(salesOrder) {
    return request({
        method: "put",
        url: '/sales',
        data: salesOrder
    })
}

// 获取销售订单详情（包含明细）
export function getSalesWithDetails(id) {
    return request({
        method: "get",
        url: `/sales/withDetails/${id}`,
    })
}

// 分页获取销售订单
export function getSalesPage(pageParams) {
    return request({
        method: "post",
        url: '/sales/page',
        data: pageParams
    })
}

// 获取销售订单列表（用于选择，排除已出库的订单）
export function getSalesForOutbound(pageParams) {
    return request({
        method: "post",
        url: '/sales/page',
        data: { ...pageParams, excludeOutbound: true }
    })
}

// 根据销售订单ID获取订单明细（用于出库单创建）
export function getSalesOrderItems(orderId) {
    return request({
        method: "get",
        url: `/sales/orderItems/${orderId}`,
    })
}